package com.facesdk;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.ByteArrayOutputStream;

/**
 * Created by linc on 15-6-18.
 */
public class Utils {

    public static byte[] Bitmap2Bytes(Bitmap bitmap) {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
         return baos.toByteArray();
     }

    public static Bitmap Bytes2Bimap(byte[] bytes) {
         if (bytes.length != 0) {
             return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
           } else {
             return null;
         }
     }

    public static byte[] intArray2byteArray(int[] data) {
        byte[] buffer = new byte[data.length];
        for (int i = 0;i<data.length;i++) {
            buffer[i] = (byte)data[i];
        }
        return buffer;
    }

    public static int[] byteArray2intArray(byte[] data) {
        int[] buffer = new int[data.length];
        for (int i = 0;i<data.length;i++) {
            buffer[i] = (int)data[i];
        }
        return buffer;
    }

}
